<script lang="ts" setup>
import { ref } from 'vue'
import { NSpace, NButton, cardProps, NDataTable, type DataTableColumns, useMessage } from 'naive-ui'
import { sendRequest } from '@/utils/api'
import VDialogContentOnlySure from '@/views/OA/Common/DialogContentOnlySure.vue'

const props = defineProps({
  ...cardProps,
  partyCode: {
    type: String
  }
})
const emit = defineEmits<{
  (event: 'close'): void
}>()

const message = useMessage()

const columns: DataTableColumns = [
  {
    title: '姓名',
    key: 'userName',
    width: '80rem',
    align: 'center',
    ellipsis: {
      tooltip: {
        contentStyle: {
          maxWidth: '400rem'
        }
      }
    }
  },
  {
    title: '性别',
    key: 'sex',
    width: '70rem',
    align: 'center',
    render(e: any) {
      return e?.sex == 1 ? '男' : e?.sex == 2 ? '女' : ''
    }
  },
  {
    title: '职务',
    key: 'position',
    width: '150rem',
    align: 'center',
    ellipsis: {
      tooltip: {
        contentStyle: {
          maxWidth: '400rem'
        }
      }
    }
  },
  {
    title: '出生日期',
    key: 'birthday',
    width: '150rem',
    align: 'center'
  },
  {
    title: '入党日期',
    key: 'partyTime',
    width: '150rem',
    align: 'center'
  },
  {
    title: '手机号',
    key: 'phone',
    width: '150rem',
    align: 'center'
  }
]

//成员表格
const tableData: any = ref([])
const loading = ref(false)
const queryTableData = async () => {
  const [error, res] = await sendRequest({
    module: 'partAffairs',
    api: 'partParsons',
    override: {
      params: {
        partyCode: props?.partyCode
      }
    }
  })
  if (error) return message.error(error.message)
  if (res.code !== 0) return message.error(res.msg)
  tableData.value = res.data?.list || []
}
queryTableData()

//确定按钮
const submit = () => {
  emit('close')
}
</script>

<template>
  <VDialogContentOnlySure title="党组织成员" @submit="submit">
    <div class="content">
      <NDataTable :bordered="false" :columns="columns" :data="tableData" :loading="loading" max-height="300" />
    </div>
  </VDialogContentOnlySure>
</template>

<style scoped>
.content {
  width: 750rem;
}
</style>
